package com.heima.feigins.fallback;

import com.heima.feigins.WemediaFigin;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.model.wemedia.pojos.WmUser;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/*
* 服务降级，相当于兜底策略一样，feign接口中方法出错，会调用这里的方法
* */
@Component("wemediaFeiginFallback") //加入到IOC容器
@Slf4j   //日志注解
public class WemediaFeiginFallback implements FallbackFactory<WemediaFigin> {

    @Override
    public WemediaFigin create(Throwable throwable) {
        return new WemediaFigin() {
            @Override
            public ResponseResult<WmUser> findByName(String name) {
                log.error("根据名称查询自媒体用户，服务远程调用出错");
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }

            @Override
            public ResponseResult<WmUser> save(WmUser wmUser) {
                log.error("保存自媒体用户，服务远程调用出错");
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }

            @Override
            public ResponseResult<WmNews> findNewsById(Integer id) {
                log.error("根据id查询自媒体文章信息，服务远程调用出错");
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }

            @Override
            public ResponseResult<WmNews> updateWmNews(WmNews wmNews) {
                log.error("修改自媒体文章信息，服务远程调用出错");
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }
        };
    }
}
